
#include <avr/io.h>
#include <stdlib.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>



#include "Main.h" // All globals are in this file 
#include "uart.h" // serial communnication routines

#include "Decode.h" // serial communnication routines


// TODO Remove ....
#define DEBUG			// Compiler flag

void Main_BugTest(void)
{
	Uart_printstr_p(PSTR("TSTX2!\n"));
}

void SlvMn_init(void){

	sei();			/* enable interrupts */

}




int main (void){

//	Decode_StateReception = 0;

#ifdef DEBUG
	LED_PORT_DIR=0xFF;
    LED_PORT =0xFE;
#endif

	// merge test
	Decode_initTimer0();// This is the last before enabling the interrupts
	Uart_init();


	Decode_PWMInit(); //initialize the output compare timer
	//initialitation complete

	SlvMn_init();// Enable the interrups


	Main_BugTest();

#ifdef DEBUG
	Uart_printstr_p(PSTR("Start!\n"));
#endif


	while (1)// Endless Loop (Main Routine )

	{
// TODO add zero cross system implemeneted with hardware

		// handle the reception from the uart here


		if (SekTmr_mSecExpired == 0xff )
		{
			SlvMn_DoRepeatedTask();
			SekTmr_mSecExpired = 0x00;// Reset the flag
		}

	}
}


void SlvMn_DoRepeatedTask (void) //This routine is called every mSec
	{
		static uint8_t m_DoFlash ;

		unsigned char  temp;


	    if( m_DoFlash == 0  )
            {
			temp = 0x41;

                LED_PORT ^=_BV(7); //XOR
//				Uart_printstr_p(PSTR("\n"));
				Uart_putchar(temp);
				temp = 0x42;
				Uart_putchar(temp);
				temp = 0x43;
				Uart_putchar(temp);
				temp = 0x0D;
				Uart_putchar(temp);

            }
            m_DoFlash++;

	

	}

